package com.qfedu.provider.aigc;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.Method;
import cn.hutool.json.JSONUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 千锋Java,为你而生！
 *
 * @Author: Feri
 * @Date:2024/11/21 14:55
 * @Modified:
 */
public class AigcHttpUtil {
    private static final String KEY="3e57bb62d919ed9c38c4c06eb18e10c6.YMC2MQ39ROmEu3mn";

    public static String createQuestion(String question){
        HttpRequest request=new HttpRequest("https://open.bigmodel.cn/api/paas/v4/chat/completions");
        request.header("Authorization","Bearer "+KEY);
        request.header("Content-Type","application/json");
        request.setMethod(Method.POST);
        Map<String,Object> param=new HashMap<>();
        param.put("model","glm-4-flash");
        List<AigcMsg> msgs=new ArrayList<>();
        param.put("messages",msgs);
        //系统 提示消息
        AigcMsg msg1=new AigcMsg("system","你叫悠享，是一名动态审核员，负责审核用户发表的动态合不合规");
        //用户 需要问的
        AigcMsg msg2=new AigcMsg("user",question);
        msgs.add(msg1);
        msgs.add(msg2);

        request.body(JSONUtil.toJsonStr(param));
        HttpResponse response=request.execute();
        System.err.println(response);
        if(response.isOk()){
            System.err.println(response.body());
        }
        return null;
    }
}
